/**
 * 蒸馏水洗涤瓶
 */
Kettle = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_KETTLE);
	},
	init:function(){		
//		var hand = new Button(this, 9, TAG_RIGHT, "#hand_right.png", this.callback);
//		hand.setPosition(cc.p(30,-31));
//		hand.setScale(0.7);
//		hand.setVisible(false);
//		var part = new Button(this, 11, TAG_RIGHT_PART, "#hand_right_part.png", this.callback);
//		part.setPosition(cc.p(30,-31));
//		part.setScale(0.7);
//		part.setVisible(false);
		var action = null;
		if(gg.flow.flow != null){
			action = gg.flow.flow.action;
		}
		if(action==ACTION_DO1){
			this.body = new Button(this, 54, TAG_KETTLE1,"#kettle.png", this.callback);		
		}else if(action==ACTION_DO2){
			this.body = new Button(this, 10, TAG_KETTLE2,"#kettle.png", this.callback);	
		}else if(action==ACTION_DO3){
			this.body = new Button(this, 10, TAG_KETTLE3,"#kettle.png", this.callback);				
		}else{
			this.body = new Button(this, 10, TAG_KETTLE4,"#kettle.png", this.callback);	
		}		
		this.body.setCascadeOpacityEnabled(true);
		this.body.setScale(0.8);
		
		var label = new cc.LabelTTF("蒸馏水",gg.fontName,22);
		label.setColor(cc.color(0,0,0));
		label.setPosition(44, 86);
		this.body.setCascadeOpacityEnabled(true);
		this.body.addChild(label, 11);

		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	callback:function(p){
		var func = cc.callFunc(this.actionDone, this);
		var action=gg.flow.flow.action;
//		var hand=this.getChildByTag(TAG_RIGHT);
//		var part=this.getChildByTag(TAG_RIGHT_PART);
		switch(p.getTag()){
		case TAG_KETTLE1:
			var move=cc.moveTo(0.6, cc.p(-268,15));
			var rotate1 = cc.rotateTo(1, -45);
			var rotate2 = cc.rotateTo(0.6, 0);
			var delay = cc.delayTime(1.7);
			var moveBack = cc.moveTo(0.6,cc.p(0,0));
			var rotate = cc.rotateTo(1, 0);
			var spaw2 = cc.spawn(moveBack,rotate);
			var seq = cc.sequence(move, func,rotate1,cc.callFunc(function() {
				this.getParent().flowRight(p,60,cc.p(10,220));
			}, this),delay,rotate2,spaw2);
			p.runAction(seq);
			break;
		case TAG_KETTLE2:						
			var move=cc.moveTo(0.6, cc.p(-160,-63));
			var rot=cc.rotateTo(0.6, 330);	
			var seq=cc.sequence(move,rot,cc.callFunc(function(){
				this.getParent().flowRight(p,60,cc.p(10,220));
				var p3=new cc.Sprite("#zhushui.png");
				p3.setPosition(-282,-112);
				this.addChild(p3);						
				var seq=cc.sequence(cc.delayTime(1.7),cc.callFunc(function() {
					p3.removeFromParent();							
				}, this));
				p3.runAction(seq);
			},this),cc.delayTime(2.1),cc.callFunc(function() {
				this.removeFromParent();
			}, this),func);
			p.runAction(seq);					
			break;
		case TAG_KETTLE3:
			var move=cc.moveTo(0.6, cc.p(-515,109));
			var rot=cc.rotateTo(0.6, 330);
			var rot1=cc.rotateTo(0.6, 0);
			var seq=cc.sequence(move,rot,cc.callFunc(function(){
				this.getParent().flowRight(p,60,cc.p(10,220));
			},this),func,cc.delayTime(1.7),rot1,cc.callFunc(function() {
				this.removeFromParent();
			}, this));
			p.runAction(seq);
			break;
		case TAG_KETTLE4:			
			var beaker=this.getParent().getChildByTag(TAG_BEAKER3);
			var move=cc.moveTo(0.6, cc.p(-310,-60));
			var rot1=cc.rotateTo(0.6, 330);
			var rot2=cc.rotateTo(0.6, 0);
			var seq=cc.sequence(move,rot1,cc.callFunc(function(){
				this.getParent().flowRight(p,60,cc.p(10,220));
				beaker.upLine();
			},this),cc.delayTime(1.5),rot2,func,cc.callFunc(function() {
				this.callNext;
				this.removeFromParent();
			}, this));
			p.runAction(seq);
			break;
		default:
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
		case TAG_KETTLE1:
			var cylinder = this.getParent().getChildByTag(TAG_CYLINDER);
			cylinder.setCascadeOpacityEnabled(true);

			var seq=cc.sequence(cc.rotateTo(1, 45),cc.callFunc(function() {
				var clyLine2 = new cc.Sprite("#line.png");
				cylinder.addChild(clyLine2);
				clyLine2.setTag(TAG_LINE);
				clyLine2.setScale(0.8,1); 
				clyLine2.setRotation(-35);
				clyLine2.setPosition(42, 48);
				clyLine2.setOpacity(0);
				var seq1=cc.sequence(cc.fadeIn(0.2),cc.moveTo(1.5,cc.p(42,247)),cc.delayTime(0.5),cc.rotateTo(1, 0));
				clyLine2.runAction(seq1);
			}, this),cc.delayTime(2),cc.rotateTo(1,0),cc.delayTime(0.5),cc.callFunc(function() {
//				var drop=new cc.Sprite("#drop.png");
//				this.addChild(drop);
//				drop.setPosition(cc.p(-420,164));
//				this.schedule(this.loadPoint, 0.7, 4, 0.2);
//				drop.runAction(cc.sequence(cc.callFunc(function() {
					var clyDtl = new cc.Sprite("#liangtong_50.png");
					clyDtl.setPosition(-520,50);
					this.addChild(clyDtl);
					
					var clyLine = new cc.Sprite("#line.png");
					clyDtl.addChild(clyLine);
					clyLine.setScale(1.2, 1);
					clyLine.setPosition(46,74);
//					clyLine.runAction(cc.moveBy(3,cc.p(0,7)));
//					var clyLine2=this.getParent().getChildByTag(TAG_CYLINDER).getChildByTag(TAG_LINE);
//					clyLine2.runAction(cc.moveBy(3, cc.p(0,3)));
//				}, this),cc.delayTime(3),cc.callFunc(function() {
//					drop.removeFromParent();
//				}, this)));
			}, this),
			cc.delayTime(2),cc.callFunc(function() {
				gg.flow.next();
				this.removeFromParent();
			}, this));
			cylinder.runAction(seq);
			

			
			
			
			break;
		case TAG_KETTLE2:
			gg.flow.next();
			break;
		case TAG_KETTLE3:
			var beaker2=this.getParent().getChildByTag(TAG_BEAKER2);
			// 水位线
			var line = new cc.Sprite("#beaker_line.png");
			line.setOpacity(0);
			line.setScale(1, 0.5);
			line.setPosition(32, 6);
			beaker2.addChild(line, 5, TAG_BEAKER2_LINE);	
			var show = cc.fadeTo(0.5,255);
			var move = cc.moveBy(1.3,cc.p(0,25));
			var seq = cc.sequence(show, move,cc.callFunc(function() {
				gg.flow.next();
			}, this));
			line.runAction(seq);
			break;
		case TAG_KETTLE4:
			gg.flow.next();
			break;		
		}
	},
	loadPoint:function(){
			var point=new cc.Sprite("#wpoint.png");
			point.setScale(0.7);
			point.setPosition(cc.p(-420,95));
			this.addChild(point);
			var move=cc.moveTo(0.6, cc.p(-420,29));			
			var seq=cc.sequence(move,cc.callFunc(function() {
				point.removeFromParent();
			}, this));
			point.runAction(seq);						
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});